package com.lorianknights.rpg.ui
{
	
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.utils.getDefinitionByName;
	import com.lorianknights.rpg.ui.templates.UITemplate;
	import com.lorianknights.rpg.ui.skins.UIGameSkin;
	import com.lorianknights.rpg.core.Player;
	import com.lorianknights.rpg.utils.Constants;
	
	public class UIGame extends UITemplate
	{
		
		private var skin:UIGameSkin;
		private var player:Player;
		
		public function UIGame()
		{
			
			super();
			
		}
		
		public override function init():void
		{
			
			this.skin = new UIGameSkin();
			addChild(this.skin);
			
				if (this.skin == null)
				{
					
					assetClass = getDefinitionByName(Constants.UI_GAME_SKIN) as Class;
					this.skin.btnBag = this.skin.getChildByName(Constants.BTN_BAG_STR) as MovieClip;
					this.skin.btnQ = this.skin.getChildByName(Constants.BTN_QUESTS_STR) as MovieClip;
					this.skin.btnPlaya = this.skin.getChildByName(Constants.BTN_PLAYA_STR) as MovieClip;
					this.skin.btnFriends = this.skin.getChildByName(Constants.BTN_FRIENDS_STR) as MovieClip;
					this.skin.btnbattle = this.skin.getChildByName(Constants.BTN_BATTLE_STR) as MovieClip;
					this.skin.btnAchievements = this.skin.getChildByName(Constants.BTN_ACHIEVEMENTS_STR) as MovieClip;
					this.skin.btnOptions = this.skin.getChildByName(Constants.BTN_OPTIONS_STR) as MovieClip;
					this.skin.btnBook = this.skin.getChildByName(Constants.BTN_BOOK_STR) as MovieClip;
					this.skin.btnGlobe = this.skin.getChildByName(Constants.BTN_GLOBE_STR) as MovieClip;
					this.skin.unm_txt = this.skin.getChildByName(Constants.UNM_TXT) as TextField;
					this.skin.lvl_txt = this.skin.getChildByName(Constants.LVL_TXT) as TextField;
					this.skin.hpbarMC = this.skin.getChildByName(Constants.HPBARMC) as MovieClip;
					this.skin.mpbarMC = this.skin.getChildByName(Constants.MPBARMC) as MovieClip;
					this.skin.hpTotal = this.skin.getChildByName(Constants.HPTOTAL) as TextField;
					this.skin.mpTotal = this.skin.getChildByName(Constants.MPTOTAL) as TextField;
					this.skin.xpTotal = this.skin.getChildByName(Constants.XPTOTAL) as TextField;
					this.skin.alliance_txt = this.skin.getChildByName(Constants.ALLIANCE_TXT) as TextField;
					this.skin = addChildAt(new assetClass(), 0) as MovieClip;
				
				}
				
				this.skin.unm_txt.text = this.player.charData.strUsername;
				this.skin.lvl_txt.text = this.player.charData.intLevel.toString();
				this.skin.hpbarMC.width = Math.round(200 * this.player.charData.intHP / this.player.charData.intHPMax);
				this.skin.mpbarMC.width = Math.round(250 / 7.5 * this.player.charData.intMP / this.player.charData.intMPMax);
				this.skin.xpbarMC.width = Math.round(200 * this.player.charData.intExp / this.player.charData.intExpToNextLevel);
				this.skin.alliance_txt.text = this.player.charData.strAlliance;
				this.skin.hpTotal.text = this.player.charData.intHP.toString() + "/" + this.player.charData.intHPMax.toString();
				this.skin.mpTotal.text = this.player.charData.intMP.toString() + "/" + this.player.charData.intMPMax.toString();
				this.skin.xpTotal.text = this.player.charData.intExp.toString() + "/" + this.player.charData.intExpToNextLevel.toString();
				this.skin.alliance_txt.text = this.player.strAlliance.toLowerCase();
				this.player.avt.updatePortrait();	
				
		}
	}
}